define(['services/services'], function (services) {
    'use strict';
    services.factory('lineServices', ['$http','apiUrl','$q', function($http,apiUrl,$q) {
        return {
            getLine:function(line_id){
                var line= {};
                var def= $q.defer();
                if(line_id!=undefined&&line_id!=""){
                    $http.get(apiUrl+"/api/v1/line?id="+line_id,{cache:true}).success(function (data) {
                        line = data.result[0];
                        line.vehiche_text = JSON.parse(line.vehiche_text);
                        line.hotel_text = JSON.parse(line.hotel_text);
                        line.image_roll = JSON.parse(line.image_roll);
                        def.resolve(line);
                    });
                }else{
                    //return line;
                    def.resolve(line);
                }
                return def.promise;
            },
            getCalendar: function (line_id) {
                var defCalendarGet= $q.defer();
                $http.get(apiUrl+"/api/v1/line/calendar?line_id="+line_id,{cache:false}).success(function (data) {
                    defCalendarGet.resolve(data.result);
                });
                return defCalendarGet.promise;
            }
        };
    }]);
});